// SettingDialog.cpp : implementation file
//

#include "stdafx.h"
#include "dxd.h"
#include "SettingDialog.h"
#include "HookDx.h"

extern BOOL g_enabled;
extern BOOL g_black;
extern int  g_limit;

// CSettingDialog dialog

IMPLEMENT_DYNAMIC(CSettingDialog, CDialog)

CSettingDialog::CSettingDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CSettingDialog::IDD, pParent)
	, m_benabled(FALSE)
	, m_bblack(FALSE)
	, m_ilimit(0)
{
	
}

CSettingDialog::~CSettingDialog()
{
}

void CSettingDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_ONCHECK, m_benabled);
	DDX_Check(pDX, IDC_BLACKCHECK, m_bblack);
	DDX_Slider(pDX, IDC_LimitSLIDER, m_ilimit);
}


BEGIN_MESSAGE_MAP(CSettingDialog, CDialog)
	ON_BN_CLICKED(IDC_ONCHECK, &CSettingDialog::OnBnClickedOncheck)
	ON_BN_CLICKED(IDC_BLACKCHECK, &CSettingDialog::OnBnClickedBlackcheck)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_LimitSLIDER, &CSettingDialog::OnNMReleasedcaptureLimitslider)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CSettingDialog message handlers

void CSettingDialog::OnBnClickedOncheck()
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	g_enabled=this->m_benabled;
	
	CString temp;
	temp.Format("%d",m_benabled);
	WritePrivateProfileString("Setting","Enable",temp,sPath);
}

void CSettingDialog::OnBnClickedBlackcheck()
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	g_black=this->m_bblack;

	CString temp;
	temp.Format("%d",m_bblack);
	WritePrivateProfileString("Setting","Black",temp,sPath);
}

void CSettingDialog::OnNMReleasedcaptureLimitslider(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	*pResult = 0;
	UpdateData(true);

	g_limit=this->m_ilimit;
	
	CString temp;
	temp.Format("%d",m_ilimit);
	WritePrivateProfileString("Setting","Limit",temp,sPath);
}

void CSettingDialog::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default

	CDialog::OnTimer(nIDEvent);

	CheckHook();
}

BOOL CSettingDialog::OnInitDialog()
{
	SetTimer(1908,3000,NULL);

	char buffer[MAX_PATH];
	GetModuleFileName(NULL, buffer, MAX_PATH);
	sPath = CString(buffer);
	sPath = sPath.Left(sPath.ReverseFind('\\'));
	sPath += "\\ids.ini";

	g_limit=m_ilimit =GetPrivateProfileInt("Setting","Limit",0,sPath);
	g_black=m_bblack =GetPrivateProfileInt("Setting","Black",0,sPath);
	g_enabled=m_benabled =GetPrivateProfileInt("Setting","Enable",0,sPath);

	UpdateData(false);

	return TRUE;
}
